﻿/*
  @Description:uan通用操作js
  @Author:zb,yangpl
  @Date:2014-07-23
*/
var pageWarZoneList = {};
pageWarZoneList.recommendlist = [];
//该方法是在列表partial页加载的时候调用的
pageWarZoneList.init = function () {
    //区经或经理推荐
    $(".btnRecommand").unbind("click");
    $(".btnRecommand").bind("click", function () {
        var propertyKeyId = $(this).attr("propertyKeyId"),
            tagNo = $(this).attr("tagNo"),
            type,
            typeName;
        if (tagNo == "100") {
            type = 1;
            typeName = "区经推荐";
        } else if (tagNo == "200") {
            type = 2;
            typeName = "经理推荐";
        }

        var reqData = { "PropertyKeyId": propertyKeyId, "PropertyRecommendType": type };
        $.AjaxAgency("/property/property-search-recommend-ajax-by-type", reqData, function (data) {
            if (data.indexOf("errorNo", 0) == -1) {
                $.artDialog({
                    title: typeName,
                    content: data,
                    lock: true,
                    okVal: "关闭",
                    ok: true
                });
            } else {
                $.artDialog();
            }
        });

    });
    //带看记录
    $(".btnTakeSeeList").bind("click", function () {
        $.dialog({
            id: "dialogTakeSeeList",
            lock: true,
            title: "带看次数",
            content: $("#popTakeSeeList").html()
        });
    });
    //业绩声明
    $(".btnPerformance").bind("click", function () {
        $.dialog({
            id: "dialogPerformance",
            lock: true,
            title: "业绩声明",
            content: $("#popPerformance").html()
        });
    });
    //发短信
    var sendMsg = function () {
        $.dialog({
            id: "dialogSms",
            lock: true,
            content: $("#popSms").html()
        });
    }
    //带看记录数据
    $('.btnTakingSee').unbind();
    $('.btnTakingSee').click(function () {
        if ($(this).attr('seecount') <= 0) {
            return false;
        }
        var propertyKeyId = $(this).attr('houseid');
        var reqData = { 'propertyKeyId': propertyKeyId };
        $.AjaxAgency('/property/GetTakeSeeListBypropertyKeyId', reqData, function (data) {

            if (data.indexOf('errorNo', 0) == -1) {
                $.artDialog({
                    title: '带看记录',
                    content: data,
                    lock: true,
                    okVal: '关闭',
                    ok: true
                });
            } else {
                $.artDialog();
            }
        });

    });


    //发布广告
    $("#btnReleaseAd").bind("click", function () {
        $.dialog({
            id: "dialogReleaseAd",
            lock: true,
            content: "此功能暂时无页面,请等待产品设计"
        }).time(3);
    });

    //收藏
    $(".collect-c").die("click");
    $(".collect-c").live("click", function () {
        var el = this;
        $(el).attr("class", "collect").attr('title', '已收藏');;
        $.AjaxAgency('/Property/Favorite', { propertyid: $(el).attr("propertyid") }, function (data) {
            if (data == "OK") {
                $(el).attr("class", "collect").attr('title', '已收藏');
            } else {
                $(el).attr("class", "collect-c");
            }
        });
    });
    //取消收藏
    $(".collect").die("click");
    $(".collect").live("click", function () {
        var el = this;
        $(el).attr("class", "collect-c").attr('title', '');
        $.AjaxAgency('/Property/favorite-cancel-ajax', { propertyid: $(el).attr("propertyid") }, function (data) {
            if (data == "OK") {
                $(el).attr("class", "collect-c").attr('title', '');
            } else {
                $(el).attr("class", "collect").attr('title', '已收藏');;
            }
        });
    });
    //简洁列表取消收藏
    $(".collect-simple").die("click");
    $(".collect-simple").live("click", function () {
        var el = this;
        $(el).remove();
        $.AjaxAgency('/Property/favorite-cancel-ajax', { propertyid: $(el).attr("propertyid") }, function (data) {
            if (data == "OK") {
                $(el).remove();
            } else {
                $(el).attr("class", "collect-simple").attr('title', '已收藏');;
            }
        });
    });
    //批量收藏
    $("#btnFavorite").unbind("click");
    $("#btnFavorite").bind("click", function () {
        var url = "/property/favorites-ajax";
        var keyIds = [];
        var objCheck = checkHouse(true);
        if (objCheck == false) {
            return false;
        }
        objCheck.each(function () {
            keyIds[keyIds.length] = $(this).attr("keyId");
        });

        var reqData = {
            "propertyKeyIds": keyIds.join(",")
        };

        $.AjaxAgency(url, reqData, function (data) {
            $.OKDialogAgency('<div class="tc">成功收藏' + data + '条房源收藏</div>', '提示', function () {
                $("#searchForm").submit();
            });
        });
    });
    //取消批量收藏
    $("#btnCancelFavorite").unbind("click");
    $("#btnCancelFavorite").bind("click", function () {
        var url = "/property/favorites-cancel-ajax";
        var keyIds = [];
        var objCheck = checkHouse(true);
        if (objCheck == false) {
            return false;
        }
        objCheck.each(function () {
            keyIds[keyIds.length] = $(this).attr("keyId");
        });

        var reqData = {
            "propertyKeyIds": keyIds.join(",")
        };

        $.AjaxAgency(url, reqData, function (data) {
            $.OKDialogAgency('<div class="tc">成功取消' + data + '条房源收藏</div>', '提示', function () {
                $("#searchForm").submit();
            });
        });
    });
    //进入流程
    $(".btnIntoWorkflow").bind("click", function () {
        $.dialog({
            id: "dialogbIntoWorkflow",
            lock: true,
            content: "此功能暂时无页面,请等待产品设计"
        }).time(3);
    });


    //所属人
    $("#btnPropertyOwner").bind("click", function () {
        $.dialog({
            id: "dialogPropertyOwner",
            lock: true,
            content: $("#popPropertyOwner").html()
        });
    });

    //TAB切换
    $(".tab-menu span").bind("click", function () {
        $(".tab-menu span").attr("class", "noselect");
        $(this).attr("class", "cur");
    });

    $("#btnTemplateMgr").bind("click", function () {
        //alert("btnTemplateMgr");
        var status = $("#smsTemplate").css("display");
        if (status == "none") {
            $("#smsTemplate").css("display", "");
        } else {
            $("#smsTemplate").css("display", "none");
        }
    });

    //看业主


    $(".see-owner,.see-owner-no").bind("click", function () {

        var currentel = this;

        $.dialog({
            id: "seeOwner",
            title: "看业主",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            width: 840,
            content: $("#seeOwner").html()
        });
        $.inputStatistics2(".aui_content div #txtClenTextarea");
        var urlNum = $(this).attr("propertyKeyid");
        $("#commonFollowType").html("");
        dataBind.bindLiLink(64, ".commonFollowType", "proertyFollow.commonFollowClick(this);");
        $.ajax({
            type: 'post',
            url: '/Property/trustors-obtain',
            data: { 'keyId': urlNum },
            success: function (data) {
                $("#seeOwnerdiv").html(data);
                $("#propertyCleanBtn").attr("pid", urlNum);
                $(currentel).attr("class", "see-owner-no");
            }
        });
        var flloweType = "<span title=\"b83a80da-adaf-4eed-94ea-3534a3491a02,2030,信息补充,list,29\">信息补充</span>";
        var state = $(this).attr("propertyStatus");
        if (state != "有效" && state != "预定") { flloweType = "<span title=\"f9c80ebc-fa67-4df8-9123-bd9acc3839e5,10,洗盘,list,29\">洗盘</span>"; }
        $("#writeFollow").find(".clearfix label,.other-inputs label").html(flloweType);
        //信息补充跟进内容

        $('.spfollowtype').unbind("click");
        $('.spfollowtype').bind("click", function (data) {
            if ($(this).text() == "不租不售") {
                $("#txtClenTextarea").val($("#txtClenTextarea").val() + "【不租不售】,原因:");
            }
            else {
                $("#txtClenTextarea").val($("#txtClenTextarea").val() + "【" + $(this).text() + "】");
            }
        });
        //常用跟进切换
        //$("#btnOtherSetsBox").unbind("hover");
        //$("#btnOtherSetsBox").hover(function () {
        //    $(this).find("ul").show();
        //    $(this).find("i").addClass("gray-down-arrow-on");
        //}, function () {
        //    $(this).find("ul").hide();
        //    $(this).find("i").removeClass("gray-down-arrow-on");
        //});

    });

    var tabObj = null;
    if ($("#imgTextList th").length >= 1) {
        tabObj = $("#imgTextList th");
    } else {
        tabObj = $('#gdWarZoneList th');
    }

    //租售价排序字段判断
    if ($("#cmbTrustType").val() == 4) {
        $('.th-price').attr('callvalue', 'RentPrice-desc');
    } else {
        $('.th-price').attr('callvalue', 'SalePrice-desc');
    }

    if ($('#hiddenSortValue').val() != '') {
        for (var i = 0; i < tabObj.length; i++) {
            if ($(tabObj[i]).attr('callValue')) {
                if ($(tabObj[i]).attr('callValue').split('-')[0] == $('#hiddenSortValue').val().split('-')[0]) {

                    if ($('#hiddenSortValue').val().split('-')[1] == 'asc') {
                        $(tabObj[i].childNodes[0]).attr('class', 'sort-up');
                        $(tabObj[i]).attr('callValue', $('#hiddenSortValue').val().split('-')[0] + '-desc');
                        break;
                    }
                    $(tabObj[i].childNodes[0]).attr('class', 'sort-down');
                    $(tabObj[i]).attr('callValue', $('#hiddenSortValue').val().split('-')[0] + '-asc');
                    break;
                }
            }
        }
    }
    //表头排序
    $('#gdWarZoneList th').unbind();
    $('#gdWarZoneList th').click(function () {
        var resultVal = $(this).attr('callValue');
        if (resultVal) {
            if (resultVal.indexOf("BuildingName") > -1 || resultVal.indexOf("HouseNo") > -1) {
                if ($("#txtEstateNames").val() != "") {
                    $('#hiddenSortValue').val(resultVal);
                    $('#searchForm').submit();
                }
                else {
                    $.OKDialogAgency('<div class="tc">此项排序需要先填写楼盘名称</div>');
                }
            }
            else {
                $('#hiddenSortValue').val(resultVal);
                $('#searchForm').submit();
            }

        }
    });
    //表头排序图文
    $('#imgTextList th').unbind();
    $('#imgTextList th').click(function () {
        var resultVal = $(this).attr('callValue');
        if (resultVal) {
            $('#hiddenSortValue').val(resultVal);
            $('#searchForm').submit();
            if ($(window).scrollTop() > $("#ajaxPages").offset().top) {
                $(window).scrollTop(0);
            }
        }
    });

    var openTemplate = function () {
        var status = $("#smsTemplate").css("display");
        if (status == "none") {
            $("#btnSend").addClass("disabled");
            $("#btnSend").attr("disabled", "disabled");
            $("#smsTemplate").css("display", "");
        } else {
            $("#btnSend").removeClass("disabled");
            $("#btnSend").attr("disabled", "false");
            $("#smsTemplate").css("display", "none");
        }
    }


    ///新js
    //工具栏按钮状态处理
    $("#gdWarZoneList input[type=checkbox]").removeAttr("checked");
    $("#ajaxPages").delegate("input[type=checkbox]", "click", function (e) {
        if ($(this).attr("checked") == "checked") {
            $(this).parents("tbody").css("background-color", "#f6f6f6");
            $(this).parents(".tbody").find(".td-div").css("border-color", "#efc75e");
            $(this).parents(".tbody").find(".tbody-tit span,.tbody-tit a,.tbody-tit em,.property-status").css("color", "#e2574c");
            $(this).parents("tbody").find(".recommend-hand").css("background-position", "-329px -101px");

            $(this).parents(".tbody").hover(function () {
                $(this).css("background-color", "#f6f6f6");
                $(this).find(".td-div").css("border-color", "#efc75e");
            });
        } else {
            $(this).parents("tbody").css("background-color", "");
            $(this).parents(".tbody").find(".td-div").css("border-color", "#eaeaea");
            $(this).parents(".tbody").find(".tbody-tit span,.property-status").css("color", "#000");
            $(this).parents(".tbody").find(".tbody-tit a").css("color", "#1f73f0");
            $(this).parents(".tbody").find(".tbody-tit em").css("color", "#a0a0a0");
            $(this).parents("tbody").find(".recommend-hand").css("background-position", "-329px -80px");

            $(this).parents(".tbody").hover(function () {
                $(this).css("background-color", "#f6f6f6");
                $(this).find(".td-div").css("border-color", "#cbcbcb");
            }, function () {
                $(this).css("background-color", "");
                $(this).find(".td-div").css("border-color", "#eaeaea");
            });
        }
        var checkedCount = $("#gdWarZoneList input[type=checkbox]:checked").length;
        if (checkedCount == 1) {


            $("#btnShow,#btnEdit,#btnReal,#btnReleaseAd,#btnSms,#btnApplicationTurntable,#btnTogetherTakeSee,#btnAdvert,#btnPropertyStatusModify,#turnShiefRightBtn,#btnCancel,#btnRecommend,#btnAdvert,#btnCancelFavorite,#btnReleaseProperty,#btnFavorite,#btnCancelFavorite").addClass("btn-blue").removeClass("edit-btn-gray");
        } else {
            $("#btnShow,#btnEdit,#btnReal,#btnReleaseAd,#btnApplicationTurntable,#turnShiefRightBtn,#btnAdvert,#btnPropertyStatusModify,#btnAdvert,#btnReleaseProperty").removeClass("btn-blue").addClass("edit-btn-gray");
        }
        if (checkedCount > 1) {
            $("#btnRecommend", "#btnCancel", "#btnCancelFavorite", "#btnTogetherTakeSee", "#btnFavorite", "#btnCancelFavorite").addClass("btn-blue").removeClass

("edit-btn-gray");
        }
        if (checkedCount < 1) {


            $("#btnAdvert,#btnShow,#btnEdit,#btnReal,#btnCancelFavorite,#btnReleaseAd,#btnSms,#btnApplicationTurntable,#btnPropertyStatusModify,#turnShiefRightBtn,#btnRecommend,#btnCancel,#btnTogetherTakeSee,#btnFavorite,#btnCancelFavorite").removeClass("btn-blue").addClass("edit-btn-gray");
        }
    });

    //插入跟进列表
    $("#gdWarZoneList .follow").bind("click", function () {
        other.showLoaderMask();
        var currentElement = $(this);
        var row = $(this).parent().parent().parent().parent();
        //图文列表页重定义row变量
        if ($("#liPictureText").attr("class") == "selected") {
            var row = $(this).parent().parent().parent();
        }
        var isOpenCurrentFollow = $(this).attr("follow-open");
        var propertyid = currentElement.attr("propertyid");
        if (isOpenCurrentFollow == "true") {
            if ($("#hidIsGraphicList").val() != "true") {
                row.next().remove();
                other.hideLoaderMask();
                $(this).attr("follow-open", "false");
            }
            else {
                row.next().next().remove();
                other.hideLoaderMask();
                $("#followdiv" + propertyid).remove();
                $(this).attr("follow-open", "false");
            }
            return;
        }
        var houseId = currentElement.attr('houseId');
        var propertyNo = currentElement.attr('propertyNo');
        var estateName = currentElement.attr('estateName');
        var salePrice = currentElement.attr('salePrice');
        var square = currentElement.attr('square');
        var rentprice = currentElement.attr('rentprice');
        var currRowIndex = row[0].rowIndex - 1;
        var columnCount = parseInt(currentElement.attr('thcount')) + 1;
        var addFollow = currentElement.attr('addfollow');
        var reqData = {
            'HouseId': houseId,
            'ColumnCount': columnCount,
            'PropertyNo': propertyNo,
            'EstateName': estateName,
            'SalePrice': salePrice,
            'Square': square,
            'AddFollow': addFollow
        };
        $.AjaxAgency("/property/follow-for-list", reqData, function (data) {
            if (data.indexOf('pageDiscription="我是错误页"') > -1) {
                $.OKDialogAgency('<div class="tc">请求失败！</div>');
            } else {
                if ($("#hidIsGraphicList").val() != "true") {
                    if (currentElement.attr("follow-open") != "true") {
                        currentElement.css("background-position", "-127px -189px");
                        $("#gdWarZoneList > tbody > tr").eq(currRowIndex).after(data);
                        currentElement.attr("follow-open", "true");
                    }

                }
                else {
                    if (currentElement.attr("follow-open") != "true") {
                        currentElement.css("background-position", "-127px -189px");
                        $('#tr' + propertyid).after(data);
                        currentElement.attr("follow-open", "true");
                    }
                }
            }
            other.hideLoaderMask();
        });

    });
    $("#gdWarZoneList .follow-simple").bind("click", function () {
        other.showLoaderMask();
        var currentElement = $(this);
        var row = $(this).parent().parent().parent();
        var isOpenCurrentFollow = $(this).attr("follow-open");
        var propertyid = currentElement.attr("propertyid");
        if (isOpenCurrentFollow == "true") {
            if ($("#hidIsGraphicList").val() != "true") {
                row.next().remove();
                other.hideLoaderMask();
                $(this).attr("follow-open", "false");
            }
            else {
                row.next().remove();
                other.hideLoaderMask();
                $("#followdiv" + propertyid).remove();
                $(this).attr("follow-open", "false");
            }
            return;
        }
        var houseId = currentElement.attr('houseId');
        var propertyNo = currentElement.attr('propertyNo');
        var estateName = currentElement.attr('estateName');
        var salePrice = currentElement.attr('salePrice');
        var square = currentElement.attr('square');
        var rentprice = currentElement.attr('rentprice');
        var currRowIndex = row[0].rowIndex - 1;
        var columnCount = parseInt(currentElement.attr('thcount')) + 1;
        var addFollow = currentElement.attr('addfollow');
        var reqData = {
            'HouseId': houseId,
            'ColumnCount': columnCount,
            'PropertyNo': propertyNo,
            'EstateName': estateName,
            'SalePrice': salePrice,
            'Square': square,
            'AddFollow': addFollow
        };
        $.AjaxAgency("/property/follow-for-list", reqData, function (data) {
            if (data.indexOf('pageDiscription="我是错误页"') > -1) {
                $.OKDialogAgency('<div class="tc">请求失败！</div>');
            } else {
                if (currentElement.attr("follow-open") != "true") {
                    currentElement.css("background-position", "-127px -189px");
                    $("#gdWarZoneList > tbody > tr").eq(currRowIndex).after(data);
                    currentElement.attr("follow-open", "true");
                }
            }
            other.hideLoaderMask();
        });

    });
    //查看业主电话
    $("#btnProprietorCellPhone").bind("click", function () {
        $.dialog({
            id: "dialogProprietorCellPhone",
            lock: true,
            content: $("#popProprietorCellPhone").html()
        });
    });



    $("#btnClose").bind("click", function () {
        $("body").css({ "overflow-x": "hidden", "overflow-y": "auto" });
        $(".wrap").css("min-height", "100%");
        $(".photoread").hide();
        $(".mask").hide();
    });

    //新增签约
    $('.icon-fanqian-no').unbind('click');
    $(".icon-fanqian-no").bind("click", function () {
        if ($(this).attr('addOnlyTrust') == 'False') {
            if ($(this).attr("class") == "icon-fanqian-no") {
                $.OKDialogAgency('<div class="tc">你没有新增签约的权限！</div>');
            }
            return false;
        }
        var currentProperty = $(this).attr('currentProperty');
        $.dialog({
            id: "dialogAddExclusive",
            lock: true,
            title: "新增签约",
            content: $("#popAddExclusive").html() + '<input type="hidden" id="currentPropertyId" value=" ' + currentProperty + '" />'
        });
        //生成上传按纽
        PopupWindow.makeUploadBtn();
        var tempGetEstateUrl = function () {
            return "/property/user-auto-complete-obtain-ajax?name=" + escape($("#btnRegisterPerson").val());
        };
        $("#btnRegisterPerson").autocomplete(tempGetEstateUrl, {
            width: 260,
            max: 12,
            selectFirst: false,
            formatItem: function (row) {
                return row.UserName + "(" + row.EmployeeNo + ")<span style='float:right'>" + row.DepartmentName + "</span>";
            },
            formatResult: function (row) {
                return row.UserName;
            }
        }).result(function (a, b) {
            var onlyTrustdiv = art.dialog.get("dialogAddExclusive").DOM.content;
            onlyTrustdiv.find("#hidUserId").val(b.UserKeyId);
            onlyTrustdiv.find("#hidUserId").attr('myValue', b.UserName);
            onlyTrustdiv.find("#hidDepartmentKeyId").val(b.DepartmentKeyId);
        });

        //设置文本域输入后剩余的字数
        $.inputStatistics2("div.aui_content #txtComment");
    });

    $('#btnShow').unbind('click');
    $('#btnShow').bind('click', function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
        }
        $('#btnShow').attr('href', '/property/details?keyId=' + objCheck.attr('keyId'));
    });

    $("#RecommendFlag").bind("change", function () {
        $('#btnSubmit').attr('isSubmitValue', 'true');
        $("#searchForm").submit();
    });

    $('#btnEdit').unbind('click');
    $('#btnEdit').click(function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
            objCheck = $('input.btnValues:checked');
            if (!PropertyRight.CheckModRight(objCheck)) {
                return false;
            }
        }
        $('#btnEdit').attr('href', '/property/property-edit?keyId=' + objCheck.attr('keyId'));
    });
    //发布房源 yjj添加
    $("#btnReleaseProperty").unbind('click');
    $("#btnReleaseProperty").click(function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
        }
        objCheck = $('input.btnValues:checked');
        if (!ListAndDetailRight.CheckRight(objCheck, "Property.PropertyAD.Set", "发布房源广告")) {
            return false;
        }

        var IsRegisterTrusts;
        var offSwitch = 0;//业主委托备案开关，默认关闭
        var trustAudit = 0;//业主委托备案审核放盘开关，默认关闭
        var data = dataBind.getRealDataByType(98);
        if (data.length > 0) {
            for (var i = 0; i < data.length ; i++) {
                if (data[i].ItemText == "业主委托开关") {
                    if (data[i].ExtendAttr == "1") {
                        IsRegisterTrusts = true;
                        offSwitch = 1;
                    }
                }
                else if (data[i].ItemText == "委托书必须审核通过才能放盘") {
                    if (data[i].ExtendAttr == "1") {
                        trustAudit = 1;

                    }
                }
            }
        }
        var HasRegisterTrusts = objCheck.attr('HasRegisterTrusts');
        //业主委托审核状态
        var RegisterTrustAudit = objCheck.attr('RegisterTrustAudit');
        //如果业主委托备案开关开启
        if (offSwitch == "1") {
            if (IsRegisterTrusts == true) {
                if (HasRegisterTrusts == 0) {
                    $.OKDialogAgency('<div class="tc">此房源为非委托房源，禁止发布房源！</div>');
                    return false;
                }
                if (RegisterTrustAudit != "1" && trustAudit == "1") {
                    $.OKDialogAgency('<div class="tc">房源委托必须为审核通过才能发布房源！</div>');
                    return false;
                }
            }
        }


        var reqData = {
            "propertyKeyId": objCheck.attr('keyId')
        };

        $.AjaxAgency('/property/property-post', reqData, function (data) {
            if (data.Flag) {
                if (data.Result != null && data.Result.ErrorNumber == '0') {
                    window.open(data.Result.RedirectUrl);
                } else {
                    $.OKDialogAgency('<div class="tc">' + data.Result.ErrorDescription + '</div>');
                }
            }
            else {
                $.OKDialogAgency('<div class="tc">' + data.ErrorMsg + '</div>');
            }
        });
    });


    //ADM 发布房源广告
    $("#btnAdvert").unbind('click');
    $("#btnAdvert").click(function () {
        var centaurl = $("#centaurl").val();
        var centaRentUrl = $("#centaRentUrl").val();
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
        }
        objCheck = $('input.btnValues:checked');

        var propertyStatus = objCheck.attr('status');
        if (propertyStatus != "有效") {
            $.OKDialogAgency('<div class="tc">非有效房源，禁止发布房源！</div>');
            return false;
        }
        //if (!ListAndDetailRight.CheckRight(objCheck, "Property.PropertyAD.Set", "发布房源广告")) {
        //    return false;
        //}
       
        var hasPhotos = objCheck.attr('HasPhotos');
        if (hasPhotos == '0') {
            $.OKDialogAgency('<div class="tc">没有房源图片，禁止发布房源！</div>');
            return false;
        }
        var propertyUsage = objCheck.attr('PropertyUsage');
        if (propertyUsage == '非商品住宅') {
            $.OKDialogAgency('<div class="tc">房屋用途为非商品住宅，禁止发布房源！</div>');
            return false;
        }
        //委托审核状态
        var RegisterTrustAudit = false;
        var offSwitch = 0;//业主委托备案开关，默认关闭
        var trustAudit = 0;//业主委托备案审核放盘开关，默认关闭
        var data = dataBind.getRealDataByType(98);
        if (data.length > 0) {
            for (var i = 0; i < data.length ; i++) {
                if (data[i].ItemText == "业主委托开关") {
                    if (data[i].ExtendAttr == "1") {
                        offSwitch = 1;
                    }
                }
                else if (data[i].ItemText == "委托书必须审核通过才能放盘") {
                    if (data[i].ExtendAttr == "1") {
                        trustAudit = 1;

                    }
                }
            }
        }
        //是否有委托备案
        var IsRegisterTrusts = objCheck.attr('HasRegisterTrusts');
        //业主委托审核状态
        RegisterTrustAudit = objCheck.attr('RegisterTrustAudit');
        //如果业主委托备案开关开启
        if (offSwitch == "1" && trustAudit == "1") {
            if (!IsRegisterTrusts || RegisterTrustAudit != "1") {
                $.OKDialogAgency('<div class="tc">此房源为非委托房源或者未审核通过委托房源，禁止发布房源！</div>');
                return false;
            }
            else if (offSwitch == "1" && trustAudit != "1") {
                if (!IsRegisterTrusts) {
                    $.OKDialogAgency('<div class="tc">此房源为非委托房源，禁止发布房源！！</div>');
                    return false;
                }

            }
        } else if (offSwitch == "1" && trustAudit != "1") {
            if (!IsRegisterTrusts) {
                $.OKDialogAgency('<div class="tc">此房源为非委托房源，禁止发布房源！</div>');
                return false;

            }
        }

        var reqData = {
            "KeyId": objCheck.attr('keyId')
        };
        var reqData2 = {
            "PropertyKeyId": objCheck.attr('keyId'),
            "TradeType": objCheck.attr('trusttype'),
            "HasRegisterTrusts": objCheck.attr('HasRegisterTrusts')
        };


        var trusttype = objCheck.attr('trusttype');
        var HasRegisterTrusts = objCheck.attr('HasRegisterTrusts');
        if (trusttype == "0") {
            $.OKDialogAgency('<div class="tc">无交易类型房源，不能发布广告！</div>');
            return false;
        }
        if (trusttype == "3") {
            $.MoreButtonDialogAgency("提示", "当前房源为租售类型房源，请选择发布出售or发布出租?", [
                             {
                                 name: '发布出售', callback: function () {
                                     //发布出售
                                     var reqData3 = {
                                         "PropertyKeyId": objCheck.attr('keyId'),
                                         "TradeType": "1"
                                     };
                                     var url = centaurl;
                                     var renturl = centaRentUrl;
                                     var remarkNo = objCheck.attr('RemarkNo');
                                     if (!remarkNo || remarkNo == "") {
                                         $.OKDialogAgency('<div class="tc">政府编号为空，禁止发布房源！</div>');
                                         return false;
                                     }
                                     CreatAndPutPropertyAd(reqData3, url, renturl, 1, 0, objCheck);
                                 }
                             },
                             {
                                 name: '发布出租', callback: function () {
                                     //发布出租
                                     var reqData4 = {
                                         "PropertyKeyId": objCheck.attr('keyId'),
                                         "TradeType": "2"
                                     };
                                     var url = centaurl;
                                     var renturl = centaRentUrl;
                                     CreatAndPutPropertyAd(reqData4, url, renturl, 1, 1, objCheck);
                                 }
                             }
            ]);
        }
        else {
            //出租、出售类型
            url = centaurl;
            renturl = centaRentUrl;
            if (trusttype == "1")
            {
                var remarkNo = objCheck.attr('RemarkNo');
                if (!remarkNo || remarkNo == "") {
                    $.OKDialogAgency('<div class="tc">政府编号为空，禁止发布房源！</div>');
                    return false;
                }
            }
            CreatAndPutPropertyAd(reqData2, url, renturl, 0, 0, objCheck);
        }
    });

    $('#btnReal').unbind('click');
    $('#btnReal').click(function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
        }
        $('#btnReal').attr('href', '/property/real?keyId=' + objCheck.attr('keyId'));
    });

    $('#btnSms').unbind('click');
    $('#btnSms').click(function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse(true);
            if (objCheck == false) {
                return false;
            }
        }
        var selectKeyId = '';
        objCheck.each(function () {
            selectKeyId += $(this).attr('keyid') + ',';
        });
        selectKeyId = selectKeyId.substr(0, selectKeyId.length - 1);

        //弹出短信
        var reqData = {
            'selectKeyIds': selectKeyId
        };

        $.AjaxAgency('/property/propety-send-message', reqData, function (data) {
            if (data == 'no') {

            } else {
                $.dialog({
                    id: "dialogCommonSms",
                    lock: true,
                    content: data
                });
            }
        });

    });

    //推荐操作
    $('#btnRecommend').unbind('click');
    $('#btnRecommend').click(function () {
        var objCheck = null;
        var temparm = "";
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                temparm = $("#operateDiv").attr("keyId");
            }
        }
        else {
            objCheck = checkHouse(true);
            if (objCheck == false) {
                return false;
            }

            var $checkedPropertyList = $("#gdWarZoneList input.btnValues:checked");
            //推荐验证 1、超出剩余推荐次数
            if ($checkedPropertyList.length > parseInt($("#recommendCount").html())) {
                $.dialog({
                    id: "recommendCountError",
                    lock: true,
                    content: '<div class="tc">您选择的房源已超出剩余' + $("#recommendCount").html() + '条，推荐失败！</div>'
                }).time(3);
                return;
            }
            //推荐验证 2、包含非有效状态房源
            if (!checkValidPropertys()) {
                $.dialog({
                    id: "propertyStatusError",
                    lock: true,
                    content: '<div class="tc">您选择的房源包含非有效状态房源，请重新选择！</div>'
                }).time(3);
                return;
            }
            //推荐验证 3、包含自己推荐过的房源
            //后端验证

            $checkedPropertyList.each(function () {
                temparm += ($(this).attr("keyId") + ",");
            });
            if (!temparm) {
                return;
            }
        }


        $.dialog({
            id: "dialogRecommends",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<div class="tc">您确定要推荐当前信息吗？</div>',
            cancel: function () { },
            ok: function () {
                $.AjaxAgency('/Property/property-recommends-ajax', { 'keyids': temparm }, function (data) {
                    var tempResult = true;
                    var alertStr = '';
                    if (!data.RecommendQuota) {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: data,
                            ok: true
                        });
                        return;
                    }
                    if (data.RecommendQuota.SuccessRecommendCount <= 0 && data.RecommendQuota.UpdateRecommendCount <= 0) {
                        alertStr = "推荐未成功";
                        tempResult = false;
                    }

                    if (tempResult) {
                        if (data.RecommendQuota.SuccessRecommendCount > 0) {
                            alertStr = '成功推荐' + data.RecommendQuota.SuccessRecommendCount + '条.';
                            $("#recommendCount").html(data.RecommendQuota.RemainingQuota);
                            for (var i = 0; i < data.OperateResult.length; i++) {
                                $("i.norecommend[keyid=" + data.OperateResult[i] + "]").attr("class", "recommend");
                            }
                        }
                        if (data.RecommendQuota.UpdateRecommendCount > 0) {
                            alertStr += '更新成功' + data.RecommendQuota.UpdateRecommendCount + '条';
                        }
                    }
                    $("#recommendAlert").html(alertStr);
                    $.dialog({
                        id: "dialogSms",
                        lock: true,
                        content: '<div class="tc">' + $("#popRecommend").html() + '</div>'
                    }, '提示', function () {
                        $("#searchForm").submit();
                    }).time(3);
                });
            }
        });


    });
    $('#btnCancel').unbind();
    $('#btnCancel').click(function () {
        var objCheck = checkHouse(true);
        if (objCheck == false) {
            return false;
        }
        var temparm = "";
        $("#gdWarZoneList input.btnValues:checked").each(function () {
            temparm += ($(this).attr("keyId") + ",");
        });
        if (!temparm) {
            return;
        }
        //if (!confirm("您确定要取消当前推荐吗？")) {
        //    return false;
        //}

        $.OKCancelDialogAgency('<div class="tc">您确定要取消当前推荐吗？</div>', '取消推荐', true, function () {
            $.ajax({
                url: "/Property/property-recommends-cancel-ajax",
                type: "POST",
                data: { "keyids": temparm },
                success: function (data) {
                    if (data.indexOf("<!DOCTYPE") > -1) {
                        $("#recommendAlert").html("取消失败");
                        return;
                    }
                    $("#recommendCount").html(data);
                    $("#recommendAlert").html("取消成功,您还剩" + data + "次推荐.");
                    $("#searchForm").submit();
                }
            });
            $.dialog({
                id: "dialogSms",
                lock: true,
                content: $("#popRecommend").html()
            }).time(3);
        });
    });
    //申请转盘逻辑,很多都是抄跟进的
    $('#btnApplicationTurntable').unbind('click');
    $('#btnApplicationTurntable').click(function () {
        var objCheck = checkHouse();
        if (objCheck == false) {
            return false;
        }
        $.dialog({
            id: "TURNToMe",
            title: "申请转盘",
            lock: true,
            content: '<div id="divFollowContent">' + $("#TURNdiv").html() + '</div>'
        });
        $("#parPropertyStatus").val("PropertyStatus=" + objCheck.attr("status"));
        $("#hidPropertyKeyId").val(objCheck.attr("keyid"));
        $("#TargetPropertyStatusKeyId3").empty();
        dataBind.bindOption(21, "select[name=TrustorTypeKeyId]"); //委托人类型
        agencyVerify.notNullInput("#addFollowForm", "#divFollowContent [notnull=notNull]", true, "blur");
        agencyVerify.mobileInput("#addFollowForm", "#divFollowContent [mobile=Mobile]", true, "blur");
        agencyVerify.NoSame("#addFollowForm", "#divFollowContent input[mobleflag=mobleFlag]", "blur");
        agencyVerify.notdefaultSelect("#addFollowForm", "#divFollowContent [name=TrustorGenderKeyId]", -1, "请选择联系人称谓", true);
        $("#divFollowContent").on("blur", "input[mobleflag=mobleFlag]", proertyFollow.mobileCheck);
        $.inputStatistics("TURNdivTextarea", 200);
        $("#addFollowForm").bind("submit", function () {
            var re = true;
            $("#addFollowForm span[type=sameCheckAjax]").each(function () {
                if ($(this).html() != "") {
                    re = false;
                }
            });
            return re;
        });
    });
     //推荐新
    $("#btnRecommend-new").bind("click", function () {
        $.dialog({
            id: "btnRecommendNew",
            title: "推荐",
            width: 255,
            lock: true,
            content: $("#btnRecommendNew").html()
        });
    });
    //转盘
    $("#turnShiefRightBtn").unbind('click');
    $("#turnShiefRightBtn").bind("click", function () {
        var objCheck;
        if ($(this).attr("tag") == "single") {
            if ($("#operateDiv").length > 0) {
                objCheck = $("#operateDiv");
            }
        }
        else {
            objCheck = checkHouse();
            if (objCheck == false) {
                return false;
            }
        }
        //要判断一下是否有转公盘或转个人权限
        var objCheck = $('input.btnValues:checked');
        var turnpublic = ListAndDetailRight.CheckTrunPRight(objCheck);
        var trunprivate = ListAndDetailRight.CheckTrunRight(objCheck);

        if ((!trunprivate) && (!turnpublic)) {
            $.OKDialogAgency('<div class="tc">你没有转该房源的权限！</div>');
            return false;
        }
        $.dialog({
            id: "turnShiefRight",
            title: "转盘",
            lock: true,
            content: $("#turnShiefRight").html()
        });
        //初始化转部门和业务员方法
        //要判断一下转盘的范围是公盘,个人,还是都有权限
        var temrang = "";
        if (turnpublic && trunprivate) {
            temrang = "all";
        }
        else if (turnpublic) {
            temrang = "public";
        }
        else if (trunprivate) {
            temrang = "private";
        }
        $("#txtTurnEmployeeName").blur(function () {
            if ($("#txtTurnEmployeeName").val() == "") {
                $("#txtTurnEmployeeName").addClass("checkError");
                if ($("#txtTurnEmployeeName").next(".wrong").length <= 0) {
                    $("#txtTurnEmployeeName").after(agencyVerify.greatErrorHtml($("#txtTurnEmployeeName"), '此项必填'));
                }
                return false;
            } else {
                $("#txtTurnEmployeeName").next(".wrong").remove();
                $("#txtTurnEmployeeName").removeClass("checkError");
                $("#btn_upstatus").removeAttr("disabled");
            }
        });
        $("#txtContractorName").blur(function () {
            if ($("#txtContractorName").val() == "") {
                $("#txtContractorName").addClass("checkError");
                if ($("#txtContractorName").next(".wrong").length <= 0) {
                    $("#txtContractorName").after(agencyVerify.greatErrorHtml($("#txtContractorName"), '此项必填'));
                }
                return false;
            } else {
                $("#txtContractorName").next(".wrong").remove();
                $("#txtContractorName").removeClass("checkError");
                $("#btn_upstatus").removeAttr("disabled");
            }
        });
        $("#CHANGESTATUSdivTextarea").blur(function () {
            if ($("#CHANGESTATUSdivTextarea").val() == "") {
            } else {
                $("#CHANGESTATUSdivTextarea").removeClass("checkError");
                $("#btn_upstatus").removeAttr("disabled");
            }
        });
        EmployeePrompt.getDepartAndEmployeeByInput("txtTurnDepartName", "hidTurnDepartKeyId", "txtTurnEmployeeName", "hidTurnEmployeeKeyId", false, temrang, 1, "", "",

    true);
        agencyVerify.NeedSmartTips("#addFollowForm", "#txtTurnDepartName", "#hidTurnDepartKeyId", "部门必需从智能提示中选择", false);
        agencyVerify.NeedSmartTips("#addFollowForm", "#txtTurnEmployeeName", "#hidTurnEmployeeKeyId", "业务员必需从智能提示中选择", false);
        EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtContractorName", "hidContractorKeyId", false, "private", 1, null, null, "请选择成交人");
        agencyVerify.NeedSmartTips("#addFollowForm", "#txtContractorName", "#hidContractorKeyId", "成交人必需从智能提示中选择", false);
        $("#TargetPropertyStatusKeyId1").empty().append('<option value="-1">保持现状</option>');
        //判断更改状态的本人、本部、全部权限
        var roleRight = $("#hidPermissions").val();
        var myDepartments = $("#hidMyDepartments").val();
        var operator = $("#hidOperatorID").val();
        var userid = objCheck.attr("userid");
        var departmentid = objCheck.attr("departmentid");
        if (roleRight.indexOf("Property.PropertyStatus.Modify-MySelf") > -1 && userid == operator) {
            proertyFollow.statusOptions(objCheck.attr("status"), "#TargetPropertyStatusKeyId1");
        } else if (roleRight.indexOf("Property.PropertyStatus.Modify-MyDepartment") > -1 && myDepartments.indexOf(departmentid) > -1) {
            proertyFollow.statusOptions(objCheck.attr("status"), "#TargetPropertyStatusKeyId1");
        } else if (roleRight.indexOf("Property.PropertyStatus.Modify-All") > -1) {
            proertyFollow.statusOptions(objCheck.attr("status"), "#TargetPropertyStatusKeyId1");
        } else {
            $("#TargetPropertyStatusKeyId1").empty().append('<option value="-1">保持现状</option>');
        }

        $("#hidPropertyKeyId").val(objCheck.attr("keyid"));
        $("#hidPropertyTrusttype1").val(objCheck.attr("trusttype"));
        agencyVerify.notNullInput("div.aui_content #addFollowForm", "div.aui_content input[notnull=notNull]", false, "blur");

        //设置文本域输入后剩余的字数

    $("#expertTransactionTypeKeyId label").click(function () {
        $("#trustorDelayShow input[name=TrustorDelay]").val(0);
        $("#trustorDelayShow input[name=TrustorDelay]").attr("checked", false);
    });
});

    //状态修改    
    $('#btnPropertyStatusModify').unbind('click');
    $('#btnPropertyStatusModify').click(function () {
        var trustType = "";
        $("#gdWarZoneList tbody tr td input.btnValues").each(function () {
            if ($(this).attr("checked")) {
                trustType = $(this).attr("trusttype");
            }
        });
        if (trustType == "0") { $.OKDialogAgency('<div class="tc">该房源没有交易类型！</div>') } else {
            var objCheck;

            if ($(this).attr("tag") == "single") {
                if ($("#operateDiv").length > 0) {
                    objCheck = $("#operateDiv");
                }
            }
            else {
                objCheck = checkHouse(true);
                if (objCheck == false) {
                    return false;
                }
            }
            objCheck = $('input.btnValues:checked');
            if (objCheck.length > 1) {
                $.OKDialogAgency('<div class="tc">房源只能选择一条！</div>');
                return false;
            }
            //if (objCheck.attr("statuscode") == "3") {
            //    $.OKDialogAgency('<div class="tc">预订状态楼盘不允许修改状态！</div>');
            //    return false;
            //}

            if (!ListAndDetailRight.CheckStatusRight(objCheck)) {
                return false;
            }
            $.dialog({
                id: "turnStatus",
                title: "状态修改",
                lock: true,
                content: $("#CHANGESTATUSdiv").html()
            });
            $("#txtContractorName").blur(function () {
                if ($("#txtContractorName").val() == "") {
                    $("#txtContractorName").addClass("checkError");
                    if ($("#txtContractorName").next(".wrong").length <= 0) {
                        $("#txtContractorName").after(agencyVerify.greatErrorHtml($("#txtContractorName"), '此项必填'));
                    }
                    return false;
                } else {
                    $("#txtContractorName").next(".wrong").remove();
                    $("#txtContractorName").removeClass("checkError");
                    $("#btn_upstatus").removeAttr("disabled");
                }
            });
            $("#CHANGESTATUSdivTextarea").blur(function () {
                if ($("#CHANGESTATUSdivTextarea").val() == "") {
                } else {
                    $("#CHANGESTATUSdivTextarea").removeClass("checkError");
                    $("#btn_upstatus").removeAttr("disabled");
                }
            });
            $("#TargetPropertyStatusKeyId2").empty();
            $("#hidPropertyKeyId").val(objCheck.attr("keyid"));

            $("#hidPropertyTrusttype").val(objCheck.attr("trusttype"));
            proertyFollow.statusOptions(objCheck.attr("status"), "#TargetPropertyStatusKeyId2");
            EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtContractorName", "hidContractorKeyId", false, "private", 1, null, null, "请选择成交人");
            agencyVerify.NeedSmartTips("#addFollowForm", "#txtContractorName", "#hidContractorKeyId", "成交人必需从智能提示中选择", false);
            agencyVerify.notNullInput("div.aui_content #addFollowForm", "div.aui_content textarea[notnull=notNull]", false, "blur");
            agencyVerify.notNullInput("div.aui_content #addFollowForm", "div.aui_content input[notnull=notNull]", false, "blur");


            //设置文本域输入后剩余的字数
            $.inputStatistics2("div.aui_content #CHANGESTATUSdivTextarea");
            propertyStatus("状态");
        }
    });



    //栋座单元多选框    
    $('#btnSelect').unbind('click');
    $('#btnSelect').click(function () {
        var estates = $("#txtEstateNames").val();
        if (estates == "") {
            $.OKDialogAgency('<div class="tc">请选择一个楼盘！</div>');
            return;
        }
        if (estates.indexOf('+') != -1) {
            $.OKDialogAgency('<div class="tc">抱歉！该功能目前不支持多个楼盘的搜索！</div>');
            return;
        }

        if ($("#txtEstateNames").val() != "") {

            //根据楼盘名称获取它下面的栋座单元
            var estateName = $("#txtEstateNames").val();
            var buildName = "";
            var reqData = {
                "EstateName": estateName,
                "BuildName": buildName,
            };
            $.AjaxAgency('/property/building-for-estate-obatin-ajax', reqData, function (data) {
                if (data != "") {
                    if (data.length > 0) {
                        var divContentHtml = "<div id='BuildNameSelectdiv' class='build-name-select-div'>";
                        divContentHtml += "<div><div class='mb20'><label><input type='checkbox' id='cheAll' /><span>全选</span></label></div>";
                        for (var i = 0; i < data.length; i++) {
                            if (i != 0 && i % 10 == 0) {
                                divContentHtml += "<div>";
                            }
                            divContentHtml += "<label><input type='checkbox' name='cheBuildingName' onclick='pageWarZoneList.SelectAllChange();' /><span>";
                            divContentHtml += data[i].BuildingName + "</span></label>";
                            if ((i + 1) % 10 == 0 && i != data.length) {
                                divContentHtml += "</div>";
                            }
                        }
                        divContentHtml += "</div>";
                        divContentHtml += "<div class='tc mt20'><input type='button' id='btnAddBuildName' class='btn-big-orange' value='提交' /></div>";
                        divContentHtml += "</div>";
                        $.dialog({
                            id: "BuildNameSelect",
                            title: "选择栋座单元",
                            lock: true,
                            content: divContentHtml
                        });
                        $("#btnAddBuildName").unbind();
                        $("#btnAddBuildName").click(function () {
                            var names = "";
                            var values = "";
                            $("#BuildNameSelectdiv").find("input[name='cheBuildingName']").each(function () {
                                if ($(this).attr("checked")) {
                                    values += $(this).next().text() + "+";
                                }
                            });
                            values = values.substr(0, values.length - 1);
                            $("#btnBuilding").val(values);
                            $(".aui_close").click();
                        })
                        $("#cheAll").unbind("click");
                        $("#cheAll").bind("click", function () {
                            if (this.checked) {
                                $("#BuildNameSelectdiv input[name='cheBuildingName']").attr('checked', true);
                            }
                            else {
                                $("#BuildNameSelectdiv input[name='cheBuildingName']").attr('checked', false);
                            }
                        })
                    }
                }
                else {
                    $.OKDialogAgency('<div class="tc">获取栋座单元失败！</div>');
                }
            });
        }
    });

    //勾选checkbox删除按钮变化
    pageWarZoneList.SelectAllChange = function () {
        var checkedCount = 0;
        $("#BuildNameSelectdiv input[name='cheBuildingName']").each(function () {
            if ($(this).attr("checked") == "checked") {
                checkedCount = checkedCount + 1;
            }
        });
        //如果列表中都勾选了，则将全选设为勾选状态
        if ($("#BuildNameSelectdiv input[name='cheBuildingName']").length == checkedCount) {
            $("#cheAll").attr("checked", true);
        }
        else {
            $("#cheAll").attr("checked", false);
        }
    }

    //常用列设置 
    $("#btnColumnSettings").unbind();
    $('#btnColumnSettings').click(function () {
        $.AjaxAgency('/property/dynamic-line-ajax', null, function (data) {
            $.dialog({
                id: "dialogColumnSettings",
                title: "常用列设置",
                width: 400,
                lock: true,
                content: data
            });
        });

    });

    //新增钥匙
    $(".keyno").bind("click", KeyModel.zoneListInsetUpdateKey);

    //推荐
    if ($(".recommend")[0]) {
        $(".recommend").die("mouseenter");
        $(".recommend").die("mouseleave");
        $(".recommend").live("mouseenter", function () {

            var currentel = $(this);
            pageWarZoneList.currentRecommend = currentel.attr("keyid");
            var recommenderDiv = $("#recommenderDiv");
            recommenderDiv.show();
            recommenderDiv.css("left", currentel.offset().left + 20);
            recommenderDiv.css("top", currentel.offset().top - 54);

            for (var j = 0; j < pageWarZoneList.recommendlist.length; j++) {
                if (pageWarZoneList.recommendlist[j].id == pageWarZoneList.currentRecommend) {
                    $("#recommenderTable").html(pageWarZoneList.recommendlist[j].html);
                    return;
                }
            }
            $("#recommenderTable").html("<tr><td>推荐人</td><td>推荐时间</td></tr>");
            $.ajax({
                url: '/property/property-search-recommend-ajax',
                type: "post",
                data: { "propertyKeyId": pageWarZoneList.currentRecommend },
                success: function (data) {
                    if (data instanceof Array) {
                        for (var i = 0; i < data.length; i++) {
                            var temstr = "<tr><td>" + data[i].split('|')[0] + "</td><td>" + data[i].split('|')[1] + "</td></tr>";
                            $("#recommenderTable").append(temstr);
                        }
                        pageWarZoneList.recommendlist.push({ 'id': pageWarZoneList.currentRecommend, 'html': $("#recommenderTable").html() });
                    } else {
                        $("#recommenderTable").append(data);
                    }
                }
            });
        }).live("mouseleave", function () {
            $("#recommenderDiv").hide();
        });
    }

    /*备注鼠标滑过弹层*/
    $(".icon-remark").hover(function () {
        $("#remark" + $(this).attr("propertyKeyid")).show();
    }, function () {
        $("#remark" + $(this).attr("propertyKeyid")).hide();
    });

    //显示操作按钮
    $(".data-table-div").bind("mouseenter", function () {

        var pid = $(this).attr("pid");
        $("#operateDiv").attr("keyId", pid);
        $("#operateDiv").show();
        $("#operateDiv").css("top", $(this).offset().top + 60);
        //$("#operateDiv").css("left", $(this).offset().left + 550);
        $("#operateDiv").css("right", 10);
        $("#btnPropertyStatusModifyData").hide();
    });
    $("#imgTextList").mouseleave(function () {
        $("#operateDiv").hide();
        $("#btnPropertyStatusModifyData").hide();
    });
    //初始化状态数据
    $('#btnPropertyStatusModifyData').html("");
    var liData = '';
    for (var i = 0; i < PropertyFilterGrouped.PropertyStatus.length; i++) {
        liData += '<li><label><input type="radio" name="propertyStatus" value="' + PropertyFilterGrouped.PropertyStatus[i].Value + '" />' + PropertyFilterGrouped.PropertyStatus[i].Name + '</label></li>';
    }
    liData += "<li id='liStatusModifyData'><input type='button' id='btnSaveStatus' class='btn-red' value='保存' /></li>";

    $('#btnPropertyStatusModifyData').html(liData);
    $('#btnSaveStatus').unbind('click');
    $('#btnSaveStatus').click(function () {
        var objCheck = checkHouse(true);
        if (objCheck == false) {
            return false;
        }
        var statusTo = $('#btnPropertyStatusModifyData input[name=propertyStatus]:checked').val();
        if (!statusTo) {
            return false;
        }
        var keyids = '';
        for (var i = 0; i < objCheck.length; i++) {
            if (i < objCheck.length - 1) {
                keyids += $(objCheck[i]).attr('keyId') + ',';
            } else {
                keyids += $(objCheck[i]).attr('keyId');
            }

        }
        $.ajax({
            url: "/Property/property-status-modify-ajax",
            type: "POST",
            data: { "keyids": keyids, "status": statusTo },
            success: function (data) {
                if (data == "OK") {
                    $.OKDialogAgency('<div class="tc">修改成功！</div>', '提示', function () {
                        $('#btnPropertyStatusModify i').attr('class', 'icon-statusModify');
                        $('#btnPropertyStatusModifyData').hide();
                        $("#searchForm").submit();
                    });
                } else {
                    $.OKDialogAgency('<div class="tc">修改失败！</div>');
                }
            }
        });
    });
    //if ($("#hidbtnColumnSetting").val() != "true") {
    //    $("#btnColumnSettings").show();
    //}
    //else {
    //    $("#btnColumnSettings").hide();
    //}
    if ($('#myHousePrompt').length > 0) {
        var keyIds = [];
        $("#gdWarZoneList .btnValues").each(function () {
            keyIds.push($(this).attr("keyid"));
        });
        $.AjaxAgency('/Property/property-update-info', { "keyIds": keyIds }, function (data) {
            $('#myHousePrompt').html(data);
        });
    }
};
pageWarZoneList.pictureTextInit = function () {
    //图文列表切换    
    $('#liPictureText').click(function () {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('true');
        $('#hidViewPattern').val(1);
        $('.pic-list-show').find('a').removeClass('selected');
        $(this).addClass("selected");
        $("#navigationBtn a").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").hide();
        $("#searchForm").submit();
        $.AjaxAgency('/property/property-pattern-memory-ajax', { req: 1 }, function (data) {
            if (data != "ok") {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
    });
    $('#liTable').click(function () {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('false');
        $('#hidViewPattern').val(2);
        $('.pic-list-show').find('a').removeClass('selected');
        $(this).addClass("selected");
        $("#navigationBtn a,#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").show();
        $("#searchForm").submit();
        $.AjaxAgency('/property/property-pattern-memory-ajax', { req: 2 }, function (data) {
            if (data != "ok") {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
    });
    $('#liTableSimple').click(function () {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('false');
        $('#hidViewPattern').val(3);
        $('.pic-list-show').find('a').removeClass('selected');
        $(this).addClass('selected');
        $("#navigationBtn a,#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").hide();
        $("#searchForm").submit();
        $.AjaxAgency('/property/property-pattern-memory-ajax', { req: 3 }, function (data) {
            if (data != "ok") {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
    });
    if ($('#hidViewPattern').val() == "GRAPHIC") {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('true');
        $("#liPictureText").addClass("selected");
        $("#liTable,#liTableSimple").removeClass("selected");
        $("#navigationBtn a,#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").hide();
    } else if ($('#hidViewPattern').val() == "LIST") {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('false');
        $("#liTable").addClass("selected");
        $("#liPictureText,#liTableSimple").removeClass("selected");
        $("#navigationBtn a,#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").show();
    } else {
        $("#hiddenSortValue").val("");
        $('#hidIsGraphicList').val('false');
        $("#liTableSimple").addClass("selected");
        $("#liPictureText,#liTable").removeClass("selected");
        $("#navigationBtn a,#navigationBtn [type=button]").removeClass().addClass("edit-btn-gray");
        $("#navigationBtn li").removeClass("on");
        $("#btnColumnSettings").hide();
    }
};

//短信模版
pageWarZoneList.openTemplate = function () {
    var status = $("#smsTemplate").css("display");
    if (status == "none") {
        $("#smsTemplate").css("display", "");
    } else {
        $("#smsTemplate").css("display", "none");
    }
};
//列表显示钥匙的div
pageWarZoneList.showKeyDiv = function (e) {
    var event = e.target || e;

    $(event).attr("isover", 1);
    var propertyKeyid = $(event).attr("propertyKeyid");
    var divid = $("#keydiv" + propertyKeyid);
    if (divid.html()) {
        divid.show();
    }
    else {
        var departmentright = ($("#gdWarZoneList .btnValues[keyid=" + propertyKeyid + "]").attr("right"));
        if (departmentright.indexOf("Property.Key.Search-All") > -1) {
            if ($("#hidPermissions").val().indexOf("Property.Key.Search-All") == -1) {
                divid.html("当前用户没有查看该楼盘钥匙的角色权限");
                divid.show();
                $(event).mouseout(function () {
                    $(event).attr("isover", 0);
                    divid.hide();
                });
                return;
            }
        }
        else {
            divid.html("当前用户没有查看该楼盘钥匙的部门权限");
            divid.show();
            $(event).mouseout(function () {
                $(event).attr("isover", 0);
                divid.hide();
            });
            return;
        }
        $.AjaxAgency("/property/property-key-div-obtain?propertyKeyId=" + propertyKeyid, null, function (data) {
            divid.html(data);
            if ($(event).attr("isover") == 1) {
                divid.show();
            }
            else {
                divid.hide();
            }
        });
    }
    $(event).mouseout(function () {
        $(event).attr("isover", 0);
        divid.hide();
    });
}


//列表显示签约的div
pageWarZoneList.showExclusiveDiv = function (e) {

    var event = e.target || e;

    $(event).attr("isover", 1);
    var OnlyTrustKeyId = $(event).attr("OnlyTrustKeyId");
    var divid = $("#exclusive" + $(event).attr("currentProperty"));
    var propertyKeyid = $(event).attr("currentProperty");
    if (divid.html()) {
        divid.show();
    } else {
        $.AjaxAgency("/property/property-only-trust-div-find-ajax?KeyId=" + OnlyTrustKeyId, null, function (data) {
            divid.html(data);
            if ($(event).attr("isover") == 1) {
                divid.show();
            } else {
                divid.hide();
            }
        });
    }
    $(event).mouseout(function () {
        $(event).attr("isover", 0);
        divid.hide();
    });
};


//列表显示押房的div
pageWarZoneList.showEntrustDiv = function (e) {

    var event = e.target || e;

    $(event).attr("isover", 1);
    var EntrustKeyId = $(event).attr("EntrustKeyId");
    var divid = $("#entrust" + $(event).attr("currentProperty"));
    var propertyKeyid = $(event).attr("currentProperty");
    if (divid.html()) {
        divid.show();
    } else {
        $.AjaxAgency("/property/property-only-Entrust-div-find-ajax?KeyId=" + EntrustKeyId + "&PropertyKeyId=" + propertyKeyid, null, function (data) {
            divid.html(data);
            if ($(event).attr("isover") == 1) {
                divid.show();
            } else {
                divid.hide();
            }
        });
    }
    $(event).mouseout(function () {
        $(event).attr("isover", 0);
        divid.hide();
    });
};

//列表页中的房源清洗
pageWarZoneList.PropertyClean = function (e) {
    var PropertyKeyId = $(e).attr("pid");

    var FollowContent = $("#txtClenTextarea").val();
    if (FollowContent == "") {
        $.OKDialogAgency('<div class="tc">请填写跟进内容</div>');
        $("#txtClenTextarea").focus();
        return;
    }
    var foltypetem = $(e).parents("#btnOtherSetsBox").siblings(".clearfix,.other-inputs").find("span").attr("title");
    //var foltypetem = dataBind.getKeyIdByTypeAndCode("29", "10") + "," + "1";
    $.AjaxAgency('/property/property-follow-add-ajax', { PropertyKeyId: PropertyKeyId, FollowContent: FollowContent, foltype: foltypetem }, function (data) {
        if (data == "ok") {
            $.OKDialogAgency('<div class="tc">添加成功！</div>', '提示', function () {
                art.dialog.get("seeOwner").close();
            });
        } else {
            $.OKDialogAgency('<div class="tc">' + data + '</div>', '提示', function () {
                art.dialog.get("seeOwner").close();
            });
        }
    });
};
//转盘成功
pageWarZoneList.TurnSucces = function (data) {
    if (data == "ok") {
        $.OKDialogAgency('<div class="tc">转盘成功！</div>', '提示', function () {
            art.dialog.get("turnShiefRight").close();
            $("#btnSubmit").click();
        });

    } else {
        $.OKDialogAgency('<div class="tc">' + data + '</div>', '提示', function () {
            art.dialog.get("turnShiefRight").close();
            $("#btnSubmit").click();
        });
    }
}
//修改状态成功
pageWarZoneList.TurnStatusSucces = function (data) {
    if (data == "ok") {
        $.OKDialogAgency('<div class="tc">状态更改成功！</div>', '提示', function () {
            art.dialog.get("turnStatus").close();
            $("#btnSubmit").click();
        });
    } else {
        $.OKDialogAgency('<div class="tc">' + data + '</div>', '提示', function () {
            art.dialog.get("turnStatus").close();
            $("#btnSubmit").click();
        });
    }
}
//申请转盘成功
pageWarZoneList.TurnToSucces = function (data) {
    if (data == "ok") {
        $.OKDialogAgency('<div class="tc">申请转盘成功！</div>');
    }
    art.dialog.get("TURNToMe").close();
    $("#btnSubmit").click();
}
$('form').submit(function () {
    pagercustomerFun();
});
//创建发布广告
function CreatAndPutPropertyAd(reqData, url, renturl, isRentSale, isRent, objCheck) {
    var propertyStatus = objCheck.attr('status');

    //导入房源广告
    $.AjaxAgency('/advert/create-propertyad', reqData, function (data) {
        if (typeof data == "string") {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
            return;
        }
        if (data.Flag && data.AdNo == null) {
            //跳转到房源编辑页
            // removeButtonDisable();
            window.open('/advert/propertyad-edit?keyid=' + data.PropertyAdKeyId);
        }
        else if (data.Flag && data.AdNo != null) {
            //状态(0-上架、1-待上架、2-已推送)
            var reqDataAd = {
                "KeyId": data.PropertyAdKeyId
            };
            if (data.Status == 0) {

                $.MoreButtonDialogAgency("提示", "房源广告已在上架区，无法再次发布!", [
                 {
                     name: '编辑', callback: function () {
                         //编辑房源广告
                         window.open('/advert/propertyad-edit?keyid=' + data.PropertyAdKeyId);
                         this.button({
                             id: 'button-disabled'
                         });
                     }
                 },
                 {
                     name: '查看详情', callback: function () {
                         //查看详情 
                         if (isRentSale == 1) {//租售类型的
                             if (isRent == 1) {
                                 window.open(renturl.format(data.AdNo));
                             }
                             if (isRent == 0) {
                                 window.open(url.format(data.AdNo));
                             }

                         }
                         if (isRentSale == 0) {//租或者售类型
                             var tradeType = objCheck.attr('trusttype');
                             if (tradeType == "1") {
                                 window.open(url.format(data.AdNo));
                             }
                             else {
                                 window.open(renturl.format(data.AdNo));
                             }
                         }
                     }
                 }
                ]);
            }
            if (data.Status == 1) {
                if (propertyStatus == "有效") {
                    $.MoreButtonDialogAgency("提示", "房源广告已在待上架区中，无法再次推送!", [
                      {
                          name: '编辑', callback: function () {
                              //编辑房源广告
                              window.open('/advert/propertyad-edit?keyid=' + data.PropertyAdKeyId);
                          }
                      },
                      {
                          name: '上架广告', callback: function () {
                              //上架房源
                              $.AjaxAgency('/advert/put-on-propertyad', reqDataAd, function (data) {
                                  if (data == "ok") {
                                      $.OKDialogAgency('上架成功！');
                                  }
                                  else {
                                      $.OKDialogAgency('<div class="tc">' + data + '</div>');
                                  }
                              });
                          }
                      }
                    ]);
                }
                else {
                    //非有效房源在待上架区
                    $.MoreButtonDialogAgency("提示", "房源广告已在待上架区中，无法再次推送!", [
                      {
                          name: '编辑', callback: function () {
                              //编辑房源广告                                                               
                              window.open('/advert/propertyad-edit?keyid=' + data.PropertyAdKeyId);
                          }
                      }
                    ]);
                }

            }
            if (data.Status == 2) {
                window.open('/advert/propertyad-edit?keyid=' + data.PropertyAdKeyId);
            }
        }
    });
}
function pagercustomerFun() {
    $('#navigationBtn a,#navigationBtn [type=button]').each(function () {
        if ($(this).attr('id') != 'btnColumnSettings') {
            $(this).attr('class', 'edit-btn-gray');
        }

    });
    other.showLoaderMask();
}

//检测房源是否被选中,isMultiple是否可以多选
function checkHouse(isMultiple) {
    var objCheck = $('input.btnValues:checked');
    if (objCheck.length == 0) {
        $.OKDialogAgency('<div class="tc">请选择房源信息！</div>');
        return false;
    } else if (objCheck.length > 1) {
        if (!isMultiple) {
            $.OKDialogAgency('<div class="tc">房源只能选择一条！</div>');
            return false;
        }

    }
    return objCheck;
}

//检测被选中的房源中是否全是有效房源
function checkValidPropertys() {
    var isValid = true;
    $("#gdWarZoneList input.btnValues:checked").each(function () {
        if ($(this).attr("statuscode") != "1") {
            isValid = false;
            return;
        }
    });
    return isValid;
};

//求两个时间的天数差 日期格式为 YYYY-MM-dd     
function daysBetween(DateOne, DateTwo) {
    var OneMonth = DateOne.substring(5, DateOne.lastIndexOf('-'));
    var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf('-') + 1);
    var OneYear = DateOne.substring(0, DateOne.indexOf('-'));

    var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf('-'));
    var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf('-') + 1);
    var TwoYear = DateTwo.substring(0, DateTwo.indexOf('-'));

    var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000);
    return cha;
}

pageWarZoneList.beginSearch = function () {
    $("#propertyboolTag :checkbox").each(function () {
        $(this).attr("disabled", "disabled");
    });
    //此方法在分页控件中
    if ("undefined" != typeof ajaxpageronbegin) {
        ajaxpageronbegin();
    }
    setPageStartTime();
};
pageWarZoneList.pageOnSuccessFun = function () {
    $("#propertyboolTag :checkbox").each(function () {
        $(this).removeAttr("disabled");
    });
    var tempCount = $('#spanUsedQuota').attr('leavequota');
    if (!(tempCount <= 0)) {
        if ($('#btnSubmit').attr('isSubmitValue') == 'true') {
            $('#btnSaveSearchCondition').css('display', 'none');
            if ($('#divJsonValue').html()) {
                if ($('#divJsonValue').html().length > 10) {
                    $('#btnSaveSearchCondition').css('display', '');
                    $('#divJson').html($('#divJsonValue').html());
                }
            }
        } else {
            if ($('#divJsonValue').html()) {
                if ($('#divJsonValue').html().length > 10) {
                    $('#btnSaveSearchCondition').css('display', '');
                    $('#divJson').html($('#divJsonValue').html());
                }
            }
        }
    }


    $("#btnAdvert,#btnShow,#btnEdit,#btnReal,#btnCancelFavorite,#btnReleaseAd,#btnSms,#btnApplicationTurntable,#btnPropertyStatusModify,#turnShiefRightBtn,#btnRecommend,#btnCancel").

    removeClass("btn-blue").addClass("edit-btn-gray");

    $("#btnFavorite,#btnTogetherTakeSee,#btnCancelTogetherTakeSee,#btnCancelFavorite").removeClass("on");
    $('#btnSubmit').attr('isSubmitValue', 'false');

    other.hideLoaderMask();
    setPageEndTime();
};

//请求失败时执行事件
pageWarZoneList.onFailureFun = function () {
    $("#propertyboolTag :checkbox").each(function () {
        $(this).removeAttr("disabled");
    });
    other.hideLoaderMask();
};
pageWarZoneList.ReplaceMessageChars = function (data) {

    data = data.replace("|方法:", "");
    data = data.replace("CreatePropertyAd", "");
    data = data.replace("CreatePropertyAdRent", "");
    data = data.replace("CreatePropertyAdSale", "");
    return data;
}
//点击空白处隐藏
pageWarZoneList.showAndHide = function (selector, id, func, id2) {
    $(document).unbind("click");
    $(document).bind("click", function (e) {
        var divpanel = $("#" + id);
        var tempoint = divpanel.offset();
        if (e.pageX > (tempoint.left + divpanel.width()) || e.pageX < tempoint.left || e.pageY > (tempoint.top + divpanel.height()) || e.pageY < tempoint.top) {
            if (id2) {
                if (e.target != $(selector)[0] && e.target != $('#' + id2)) {
                    divpanel.hide();
                    if (func) {
                        func();
                    }
                    $(document).unbind("click");
                }
            } else {
                if (e.target != $(selector)[0]) {
                    divpanel.hide();
                    if (func) {
                        func();
                    }
                    $(document).unbind("click");
                }
            }

        }
    });
};

//页面加载
$(function () {
    //if ($("#hidbtnColumnSetting").val() == "true") {
    //    $("#btnColumnSettings").hide();
    //}
    $("input[type=reset]").bind("click", function () {
        $("input[name=chbpropertyStatusSelect]").removeAttr("checked");
    });

    //发布房源临时弹框
    $("#btnReleaseProperty1,#btnMyAds1,#btnAdsPosted1,#btnAdsPostFailed1").on("click", function () {
        $.dialog({
            id: "btnReleaseProperty1",
            lock: true,
            title: "友情提示",
            width: 300,
            height: 150,
            content: '<center style="font-size:25px;">暂未开放...</center>'
        });
    });
});

